﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.Xml;

namespace UMLDraw
{
    //объявление класса Рабочее поле
    public class WorkPlace
    {
        public string Name;
        public int ActualState;
        public int ActualTransfer;
        public int ActualComment;
        public string CurrentAction;                 //текущее действие пользователя
        public TreeNode tree;
        public int WorkPlaceWidht;
        public int WorkPlaceHeight;
        public string path;
        public double Scale;

        public WorkPlace()
        {
            Name = "Рабочее поле";
            ActualState = 0;
            ActualTransfer = 0;
            ActualComment = 0;
            CurrentAction = "SelectItem";
            tree = new TreeNode(Name);
            tree.Name = Name;
            tree.Text = Name;
            WorkPlaceWidht = 2000;
            WorkPlaceHeight = 2000;
            path = "";
            Scale = 1;
        }

        public void Initialize(string name, int AS, int AT, int AC, int X, int Y)
        {
            Name = name;
            tree.Text = name;
            ActualState = AS;
            ActualTransfer = AT;
            ActualComment = AC;
            WorkPlaceWidht = X;
            WorkPlaceHeight = Y;
            path = "";
        }
        public void refreshAll()
        {
            for (int i = 0; i < UMLDraw.MainForm.STate.Count(); i++)
            {
                UMLDraw.MainForm.STate[i].Image.Refresh();
                UMLDraw.MainForm.STate[i].Image.BringToFront();
                UMLDraw.MainForm.STate[i].Names.Refresh();
                UMLDraw.MainForm.STate[i].Names.BringToFront();
                UMLDraw.MainForm.STate[i].Entrys.Refresh();
                UMLDraw.MainForm.STate[i].Entrys.BringToFront();
                UMLDraw.MainForm.STate[i].Dos.Refresh();
                UMLDraw.MainForm.STate[i].Dos.BringToFront();
                UMLDraw.MainForm.STate[i].Exits.Refresh();
                UMLDraw.MainForm.STate[i].Exits.BringToFront();
            }

            for (int i = 0; i < UMLDraw.MainForm.CMent.Count(); i++)
            {
                UMLDraw.MainForm.CMent[i].Image.Refresh();
                UMLDraw.MainForm.CMent[i].Image.BringToFront();
                UMLDraw.MainForm.CMent[i].Names.Refresh();
                UMLDraw.MainForm.CMent[i].Names.BringToFront();
            }
            UMLDraw.MainForm.IPut.Image.Refresh();
            UMLDraw.MainForm.IPut.Image.BringToFront();
            UMLDraw.MainForm.OPut.Image.Refresh();
            UMLDraw.MainForm.OPut.Image.BringToFront();
        }

        public void selectSth(string name)
        {
            for (int i = 0; i < UMLDraw.MainForm.STate.Count(); i++)
            {
                if (UMLDraw.MainForm.STate[i].Name == name)
                {
                    UMLDraw.MainForm.STate[i].isSelected = true;
                    for (int j = 0; j < 4; j++)
                        UMLDraw.MainForm.STate[i].Marks[j].Show();
                }
                else
                {
                    UMLDraw.MainForm.STate[i].isSelected = false;
                    for (int j = 0; j < 4; j++)
                        UMLDraw.MainForm.STate[i].Marks[j].Hide();
                }
            }
            for (int i = 0; i < UMLDraw.MainForm.CMent.Count(); i++)
            {
                if (UMLDraw.MainForm.CMent[i].Name == name)
                {
                    UMLDraw.MainForm.CMent[i].isSelected = true;
                    for (int j = 0; j < 4; j++)
                        UMLDraw.MainForm.CMent[i].Marks[j].Show();
                }
                else
                {
                    UMLDraw.MainForm.CMent[i].isSelected = false;
                    for (int j = 0; j < 4; j++)
                        UMLDraw.MainForm.CMent[i].Marks[j].Hide();
                }
            }

            if (UMLDraw.MainForm.IPut.Name == name)
            {
                try
                {
                    UMLDraw.MainForm.IPut.isSelected = true;
                    for (int j = 0; j < 4; j++)
                        UMLDraw.MainForm.IPut.Marks[j].Show();
                }
                catch { }
            }
            else
            {
                try
                {
                    UMLDraw.MainForm.IPut.isSelected = false;
                    for (int j = 0; j < 4; j++)
                        UMLDraw.MainForm.IPut.Marks[j].Hide();
                }
                catch { }
            }

            if (UMLDraw.MainForm.OPut.Name == name)
            {
                try
                {
                    UMLDraw.MainForm.OPut.isSelected = true;
                    for (int j = 0; j < 4; j++)
                        UMLDraw.MainForm.OPut.Marks[j].Show();
                }
                catch { }
            }
            else
            {
                try
                {
                    UMLDraw.MainForm.OPut.isSelected = false;
                    for (int j = 0; j < 4; j++)
                        UMLDraw.MainForm.OPut.Marks[j].Hide();
                }
                catch { }
            }
            
        }
    }
}
